package com.lz.autotest.project.testmanage.autoTest.service.Listener;

import cn.hutool.core.map.MapUtil;
import cn.hutool.json.JSONUtil;
import com.lz.autotest.common.utils.GlobalMap;
import com.lz.autotest.project.testmanage.autoTest.entity.ResultView;
import com.lz.autotest.project.testmanage.autoTest.service.thread.SendDataThreadPool;
import com.lz.autotest.project.websocketApi.netty.post.pusher;

import java.util.Map;

/**
 * @author: X
 * @date: Created in 2023/6/30 9:36
 * @Description:
 */
public class SendDataListener extends Listener {

    public SendDataListener(String listenerType, Integer priority) {
        super(listenerType, priority);
    }

    @Override
    public void execute(Map<String, Object> map) {
        SendDataThreadPool.execute(new Runnable() {
            @Override
            public void run() {
                String reportId =    MapUtil.getStr(map,"reportId");
                String result =    MapUtil.getStr(map,"result");
                String ip =    MapUtil.getStr(map,"ip");
                pusher.sendOneMsg(ip, result);
                //放入内存中等待前端消费
                String reportIdTemp = (String) map.get("reportId");
                ResultView resultViewTemp = JSONUtil.toBean( MapUtil.getStr(map,"result"),ResultView.class);
                GlobalMap.putInfResult(reportIdTemp, resultViewTemp);

            }
        });
    }
}
